package work;

import java.io.*;
import java.util.ArrayList;

public class Copy {
    public void copyFile(String file1, String file2) {
        FileInputStream fileIn = null;
        ArrayList<Integer> arrayList = new ArrayList();
        try {
            fileIn = new FileInputStream(file1);
            int d = 0;

            while ((d = fileIn.read()) != -1) {
                arrayList.add(d);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileIn != null) {
                try {
                    fileIn.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        FileOutputStream fileOut = null;
        try {
            fileOut = new FileOutputStream(file2);
            for (Integer obj : arrayList) {
                fileOut.write(obj);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileOut != null) {
                try {
                    fileOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        Copy copy = new Copy();
        copy.copyFile("d:/1.JPG", "d:/c.JPG");
    }
}
